package scratch.InfoEssentials;

import java.text.SimpleDateFormat;
import java.util.Calendar;

public class FetchInfo {
	private static NetAccess netAccess = NetAccess.getInstance();

	/**
	 * @param infoNode
	 */
	public static void fetch(InfoNode infoNode) {
		String source = netAccess.fetchSource(infoNode.getUrl());

		int startIndex = 0;
		int endIndex = 0;

		/* fetch title */
		startIndex = source.indexOf("<title>") + 7;
		endIndex = source.indexOf("|", startIndex);

		infoNode.setTitle(source.substring(startIndex, endIndex));

		/* fetch forum */
		startIndex = endIndex + 1;
		endIndex = source.indexOf(" - ", endIndex);

		infoNode.setForum(source.substring(startIndex, endIndex));

		/* fetch postTime */
		startIndex = source.indexOf("fl gray")+16;
		System.out.println(source.substring(startIndex,startIndex+20));
		endIndex = startIndex + 16;

		infoNode.setPostTime(source.substring(startIndex, endIndex));

		/* fetch reportTime */
		Calendar calendar = Calendar.getInstance();
		String pattern = "yyyy-MM-dd HH:mm";
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern);
		
		infoNode.setReportTime(simpleDateFormat.format(calendar.getTime()));
		
//		/*fetch summary*/
//		startIndex = source.indexOf("read_tpc",endIndex+1)+10;
//		endIndex = source.indexOf("</div>",startIndex);
//		
//		infoNode.setSummary(source.substring(startIndex,endIndex));
		
		
		
	}

	public static void main(String[] args) {

	}
}
